package com.example.demo.DBServer.targetDatabase;

import com.example.demo.entity.TableColumnEntity;
import org.apache.ibatis.annotations.*;

import javax.annotation.sql.DataSourceDefinition;
import java.util.List;
import java.util.Map;

@Mapper
public interface DBServerDao {

    /**
     * 从数据库查询删除或归档数据需要的列的信息
     * @param sql
     * @return
     */
    @Select({})
    List<Map<String,Object>> getParamsByCondition(String sql);

    /**
     * 数据归档时用来插入数据
     * @param sql
     * @return
     */
    @Insert({})
    Integer dataArchive(String sql);

    /**
     * 查询建表的sql语句
     * @param sql
     * @return
     */
    @Select({})
    Map<String, String> getCreateTableSql(String sql);

    /**
     * 查询表的列的信息
     */
    @Select({})
    @Results(id = "columnMap",
            value = {
                    @Result(column = "COLUMN_NAME", property = "columnName"),
                    @Result(column = "DATA_TYPE", property = "dataType"),
                    @Result(column = "COLUMN_COMMENT", property = "columnComment"),
                    @Result(column = "CHARACTER_MAXIMUM_LENGTH", property = "characterMaximumLength")
    })
    List<TableColumnEntity> getTableColumnInfo(String sql);

    /**
     * 新建表
     * @param sql
     */
    @Update({})
    void createTable(String sql);

    /**
     * 删除表中数据
     * @param sql
     * @return
     */
    @Delete({})
    Integer deleteDataByCondition(String sql);

    /**
     * 查询建表的sql语句
     * @param sql
     * @return
     */
    @Select({})
    Integer countBySql(String sql);

    /**
     * 输出表
     */
    @Delete({})
    boolean dropTable(String sql);

}
